package com.team.arms.common;

import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.util.Map;

@Data
@ApiModel("返回类")
/**
 * 返回结果的统一实体类
 */
public class Result2 {
    private boolean flag; //是否成功
    private int statusCode; //状态码
    private String message; //提示信息
    private Object data; //数据

    public Result2() {
    }

    public Result2(boolean flag, StatusCode statusCode, String message, Object data) {
        this.flag = flag;
        this.statusCode = statusCode.getCode();
        this.message = message;
        this.data = data;
    }

    public Result2(boolean flag, int statusCode, String message, Object data) {
        this.flag = flag;
        this.statusCode = statusCode;
        this.message = message;
        this.data = data;
    }

    public static Result2 success() {
        return new Result2(true, StatusCode.OK, "执行成功", null);
    }

    public static Result2 success(String message) {
        return new Result2(true, StatusCode.OK, message, null);
    }


    public static Result2 error() {
        return new Result2(false, StatusCode.ERROR, "执行出错", null);
    }

    public static Result2 error(String message) {
        return new Result2(false, StatusCode.ERROR, message, null);
    }

    public static Result2 error(StatusCode statusCode, String message) {
        return new Result2(false, statusCode, message, null);
    }


    public Result2 data(Object data) {
        this.data = data;
        return this;
    }

    public Result2 data(Map<String, Object> map) {
        this.data = map;
        return this;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public Result2 setStatusCode(StatusCode statusCode) {
        this.statusCode = statusCode.getCode();
        return this;
    }

    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }


    public String getMessage() {
        return message;
    }

    public Result2 message(String message) {
        this.message = message;
        return this;
    }

    public Object getData() {
        return data;
    }

    public boolean isFlag() {
        return flag;
    }
}
